/*矩形类*/
export class Rectangle {
  //region # 字段及构造器
  /**
   * 矩形 有参构造器
   * @param color - 边框颜色
   * @param  x - 左上角X
   * @param y - 左上角Y
   * @param width - 宽
   * @param height - 高
   * @param scale - 缩放系数
   * */
  constructor(color: string, x: number, y: number, width: number, height: number, scale: number) {
    this.color = color
    this.x = x
    this.y = y
    this.width = width
    this.height = height
    this.isSelected = false
    this.scale = scale
  }

  //endregion

  //region # 属性

  //region 边框颜色 —— color:string
  /*边框颜色*/
  public color: string
  //endregion
  //region 左上角X —— x:number
  /*左上角X*/
  x: number
  //endregion
  //region 左上角Y —— y:number
  /*左上角Y*/
  y: number
  //endregion
  //region 宽 —— width:number
  /*宽*/
  width: number
  //endregion
  //region 高 —— height:number
  /*高*/
  height: number
  //endregion
  //region 缩放系数 —— scale:number
  /*缩放系数*/
  scale: number
  //endregion
  //region 是否选中 —— isSelected:boolean
  /*是否选中*/
  isSelected: boolean
  //endregion

  //#endregion

  //region # 方法

  get minX() {
    return Math.min(this.x, this.x + this.width)
  }

  get minY() {
    return Math.min(this.y, this.y + this.height)
  }

  get maxX() {
    return Math.max(this.x, this.x + this.width)
  }

  get maxY() {
    return Math.max(this.y, this.y + this.height)
  }
  //绘制
  draw(ctx: CanvasRenderingContext2D) {
    if (ctx) {
      ctx.strokeStyle = this.color
      ctx.strokeRect(
        this.x * this.scale,
        this.y * this.scale,
        this.width * this.scale,
        this.height * this.scale,
      )
      ctx.lineWidth = 2
    }
  }

  //写颜色
  setcolor(type: number) {
    if (type == 0) {
      this.color = '#FF3F4C'
      this.isSelected = false
    } else {
      this.color = '#407cff'
      this.isSelected = true
    }
  }
  //endregion
}
